package com.yx.config;

import com.yx.constatns.RabbitMQConstatns;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Classname RabbitMQConfig
 * @Date 2021/07/12 17:17
 * @Author by yx
 * @Description TODO:
 */
@Configuration
public class RabbitMQConfig {

    /*
    * 创建一个交换机
    * */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(RabbitMQConstatns.GOODS_EXCHANGE, true, false);
    }

    @Bean
    public Queue queue(){
        // exclusive 设置未true,如果没有设置死性队列会出错
        return  new Queue(RabbitMQConstatns.GOODS_QUEUE, true, false, false);
    }

    @Bean
    public Binding binding(){
        return BindingBuilder.bind(queue()).to(topicExchange()).with("shop.goods.*");
    }
}
